package pzl.com.canvasapi.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;

import pzl.com.canvasapi.L;

/**
 * @author zl.peng
 * @version [1.0, 2016-11-17]
 *          //todo 未完?
 */
public class V_RestoreToCount extends View {
    int flag = 0;
    /**
     * 没有save没有restore
     */
    static final int normal = 0;

    public V_RestoreToCount(Context context) {
        super(context);
    }

    public V_RestoreToCount(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public V_RestoreToCount(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        Paint p = new Paint();
        TextPaint tp = new TextPaint();
        tp.setTextSize(22);
        p.setAntiAlias(true);
        p.setColor(Color.CYAN);
        p.setStyle(Paint.Style.FILL_AND_STROKE);

        Rect rect1 = new Rect();
        rect1.left = 0 + 15;
        rect1.right = getWidth() - 15;
        rect1.top = 0 + 15;
        rect1.bottom = rect1.top + 700;
        int saveIdA = canvas.save();
        L.i("saveIdA=" + saveIdA);
        canvas.drawRect(rect1, p);
        canvas.drawText("A", rect1.left + 20, rect1.top + 20, tp);

        Rect rect2 = new Rect();
        rect2.left = rect1.left + 40;
        rect2.right = rect1.right - 40;
        rect2.top = rect1.top + 40;
        rect2.bottom = rect1.bottom - 40;
        p.setColor(Color.parseColor("#cf8282"));
        int saveIdB = canvas.save();
        L.i("saveIdB=" + saveIdB);
        canvas.drawRect(rect2, p);
        canvas.drawText("B", rect2.left + 20, rect2.top + 20, tp);

        Rect rect3 = new Rect();
        rect3.left = rect2.left + 40;
        rect3.right = rect2.right - 40;
        rect3.top = rect2.top + 40;
        rect3.bottom = rect2.bottom - 40;
        p.setColor(Color.parseColor("#c5b3ec"));
        int saveIdC = canvas.save();
        L.i("saveIdC=" + saveIdC);
        canvas.drawRect(rect3, p);
        canvas.drawText("C", rect3.left + 20, rect3.top + 20, tp);

        Rect rect4 = new Rect();
        rect4.left = rect3.left + 40;
        rect4.right = rect3.right - 40;
        rect4.top = rect3.top + 40;
        rect4.bottom = rect3.bottom - 40;
        p.setColor(Color.parseColor("#d3f1cb"));
        int saveIdD = canvas.save();
        L.i("saveIdD=" + saveIdD);
        canvas.drawRect(rect4, p);
        canvas.drawText("D", rect4.left + 20, rect4.top + 20, tp);

        Rect rect5 = new Rect();
        rect5.left = rect4.left + 80;
        rect5.right = rect4.right - 80;
        rect5.top = rect4.top + 80;
        rect5.bottom = rect4.bottom - 80;
        p.setColor(Color.parseColor("#59c737"));
        int saveIdE = canvas.save();
        L.i("saveIdE=" + saveIdE);
        canvas.drawRect(rect5, p);
        canvas.drawText("E", rect5.left + 20, rect5.top + 20, tp);

        //canvas.restoreToCount(saveIdC);
        //canvas.rotate(90, getWidth() / 2, 15 + 700 / 2);
        p.setColor(Color.BLACK);
        p.setStrokeWidth(10);
        canvas.drawLine(0, 350, getWidth(), 350, p);

    }

    public void simple() {
        flag = normal;
        invalidate();
    }

}
